<template>
  <view class="content">
    <div class="lean-bg">
      <img src="/static/bg.png" alt="" />
    </div>
    <view class="store-content">
      <scroll-view
        enableBackToTop="true"
        lower-threshold="250"
        @scrolltolower="loadmore()"
        scroll-with-animation
        scroll-y
        class="scoll-page"
      >
        <storeList :res="storeList" type="oneColumns" />
        <uni-load-more
          :status="loadingType"
          @loadmore="loadmore()"
        ></uni-load-more>
      </scroll-view>
    </view>
    <div class="empty" v-if="empty">
      <view
        ><image
          style="width: 360rpx; height: 260rpx"
          src="/static/nodata.png"
        ></image
      ></view>
      <view>
        <p class="tip-1">暂无搜索记录</p>
        <p class="tip-2">小伙伴努力录入中～</p>
      </view>
    </div>
    <u-back-top :scroll-top="scrollTop"></u-back-top>
  </view>
</template>

<script>
import { getFloorData } from "@/api/home"; //获取楼层装修接口
import { getGoodsList, getGoodsRelated } from "@/api/goods.js";
import storeList from "@/components/m-store-list/list.vue";
export default {
  data() {
    return {
      storeList: [
        {
          storeName: "店铺名称",
          storeDesc:
            "店铺简介店铺简介店铺简介店铺简介店铺简介店铺简介店铺简介店铺简介",
          storeImg:
            "https://lilishop-oss.oss-cn-beijing.aliyuncs.com/9eb6aab6bf614175b936830bd806eb20.jpg?x-oss-process=style/200X200",
          goodsList: [
            {
              goodsPrice: "23.00",
              goodsImg:
                "https://lilishop-oss.oss-cn-beijing.aliyuncs.com/9eb6aab6bf614175b936830bd806eb20.jpg?x-oss-process=style/200X200",
            },
            {
              goodsPrice: "23.00",
              goodsImg:
                "https://lilishop-oss.oss-cn-beijing.aliyuncs.com/9eb6aab6bf614175b936830bd806eb20.jpg?x-oss-process=style/200X200",
            },
            {
              goodsPrice: "23.00",
              goodsImg:
                "https://lilishop-oss.oss-cn-beijing.aliyuncs.com/9eb6aab6bf614175b936830bd806eb20.jpg?x-oss-process=style/200X200",
            },
            {
              goodsPrice: "23.00",
              goodsImg:
                "https://lilishop-oss.oss-cn-beijing.aliyuncs.com/9eb6aab6bf614175b936830bd806eb20.jpg?x-oss-process=style/200X200",
            },
            {
              goodsPrice: "23.00",
              goodsImg:
                "https://lilishop-oss.oss-cn-beijing.aliyuncs.com/9eb6aab6bf614175b936830bd806eb20.jpg?x-oss-process=style/200X200",
            },
            {
              goodsPrice: "23.00",
              goodsImg:
                "https://lilishop-oss.oss-cn-beijing.aliyuncs.com/9eb6aab6bf614175b936830bd806eb20.jpg?x-oss-process=style/200X200",
            },
          ],
        },
        {
          storeName: "店铺名称",
          storeDesc:
            "店铺简介店铺简介店铺简介店铺简介店铺简介店铺简介店铺简介店铺简介",
          storeImg:
            "https://lilishop-oss.oss-cn-beijing.aliyuncs.com/9eb6aab6bf614175b936830bd806eb20.jpg?x-oss-process=style/200X200",
          goodsList: [
            {
              goodsPrice: "23.00",
              goodsImg:
                "https://lilishop-oss.oss-cn-beijing.aliyuncs.com/9eb6aab6bf614175b936830bd806eb20.jpg?x-oss-process=style/200X200",
            },
            {
              goodsPrice: "23.00",
              goodsImg:
                "https://lilishop-oss.oss-cn-beijing.aliyuncs.com/9eb6aab6bf614175b936830bd806eb20.jpg?x-oss-process=style/200X200",
            },
            {
              goodsPrice: "23.00",
              goodsImg:
                "https://lilishop-oss.oss-cn-beijing.aliyuncs.com/9eb6aab6bf614175b936830bd806eb20.jpg?x-oss-process=style/200X200",
            },
            {
              goodsPrice: "23.00",
              goodsImg:
                "https://lilishop-oss.oss-cn-beijing.aliyuncs.com/9eb6aab6bf614175b936830bd806eb20.jpg?x-oss-process=style/200X200",
            },
            {
              goodsPrice: "23.00",
              goodsImg:
                "https://lilishop-oss.oss-cn-beijing.aliyuncs.com/9eb6aab6bf614175b936830bd806eb20.jpg?x-oss-process=style/200X200",
            },
            {
              goodsPrice: "23.00",
              goodsImg:
                "https://lilishop-oss.oss-cn-beijing.aliyuncs.com/9eb6aab6bf614175b936830bd806eb20.jpg?x-oss-process=style/200X200",
            },
          ],
        },
      ],
      pageData: "", //楼层页面数据
      empty: false,
      scrollTop: 0,
      goodsList: [],
      loadingType: "more", //加载更多状态
      cateList: [],
      params: {
        pageNumber: 1,
        pageSize: 10,
        // sort: 'grade_asc',
        keyword: "",
      },
      sortParams: {
        pageNumber: 1,
        pageSize: 10,
        categoryId: "",
      },

      routerVal: "",
    };
  },

  onPageScroll(e) {
    this.scrollTop = e.scrollTop;
  },
  onLoad(val) {
    this.init();
    this.routerVal = val;

    // 有值
    if (this.routerVal.category) {
      this.params.categoryId = this.routerVal.category;
      this.sortParams.categoryId = this.routerVal.category;
      this.isShowSeachGoods = true;
      this.$nextTick(() => {
        this.$refs.mSearch.isShowSeachGoods = true;
      });
    }
    if (this.routerVal.keyword) {
      this.params.keyword = this.routerVal.keyword;
      this.isShowSeachGoods = true;
    }
    if (this.routerVal.storeId) {
      this.params.storeId = this.routerVal.storeId;
      this.isShowSeachGoods = true;
    }
    if (this.routerVal.promotionType) {
      this.params.promotionType = this.routerVal.promotionType;
      this.isShowSeachGoods = true;
    }
    if (this.routerVal.promotionsId) {
      this.params.promotionsId = this.routerVal.promotionsId;
      this.isShowSeachGoods = true;
    }
    this.loadData();
  },
  components: {
    storeList,
  },
  watch: {},

  onReachBottom() {
    this.params.pageNumber++;
    this.loadData();
  },

  mounted() {},

  methods: {
    init() {
      this.getFloorData();
    },
    getFloorData() {
      this.pageData = "";
      getFloorData().then((res) => {
        if (res.data.success) {
          const result = JSON.parse(res.data.result.pageData);
          this.pageData = result;
          if (result.list.length) {
            // 如果最后一个装修模块是商品模块的话 默认启用自动加载
            result.list[result.list.length - 1]
              ? result.list[result.list.length - 1].model == "goods"
                ? (this.enableLoad = true)
                : ""
              : "";
          }
        }
      });
    },
    back() {
      uni.navigateBack({
        delta: 1,
      });
    },
    loadmore() {
      this.params.pageNumber++;
      this.loadData();
    },

    //加载商品 ，带下拉刷新和上滑加载
    async loadData(type, loading) {
      this.loadingType = "loading";
      if (type == "refresh") {
        this.goodsList = [];
      }
      //没有更多直接返回 #TODO
      let goodsList = await getGoodsList(this.params);
      if (goodsList.data.result.records.length < 10) {
        this.loadingType = "noMore";
        this.empty = true;
      } else {
        this.empty = false;
      }
      this.goodsList.push(...goodsList.data.result.records);

      if (this.$store.state.isShowToast) {
        uni.hideLoading();
      }
    },
  },
};
</script>
<style lang="scss" scoped>
@import "./brand.scss";
</style>
